package com.eedi.framework.user.controller.org;

import com.eedi.framework.common.pojo.CommonResult;
import com.eedi.framework.user.controller.org.vo.OrgUserProfileEditPwdReq;
import com.eedi.framework.user.controller.org.vo.OrgUserProfileEditReq;
import com.eedi.framework.user.service.OrgUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.eedi.framework.common.pojo.CommonResult.success;
import static com.eedi.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

/**
 * 个人中心
 * @author zybourn
 */
@Tag(name = "经营管理 - 个人中心")
@RestController
@RequestMapping("/org/user-profile")
@Validated
public class OrgProfileController {

    @Resource
    OrgUserService orgUserService;

    @PostMapping("/edit-info")
    @Operation(summary = "修改个人信息(org:user:update)")
    @PreAuthorize("@org.hasPermission('org:user:update')")
    public CommonResult<Boolean> editInfo(@RequestBody OrgUserProfileEditReq req) {
        orgUserService.editOrgUserInfo(getLoginUserId(), req);
        return success(true);
    }

    @PostMapping("/edit-pwd")
    @Operation(summary = "修改密码(org:user:update)")
    @PreAuthorize("@org.hasPermission('org:user:update')")
    public CommonResult<Boolean> editPwd(@RequestBody OrgUserProfileEditPwdReq req) {
        orgUserService.editPwd(getLoginUserId(), req);
        return success(true);
    }
}
